package cn.wen.java.sql;

import java.math.BigDecimal;
import java.util.Date;
import java.sql.Blob;
import java.sql.Time;
import java.sql.Timestamp;
import java.sql.Types;

/**
 * Title：各种SQL数据类型与JAVA数据类型的映射。
 * <p>
 * Description：
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2011/9/7 Description：初完成。
 *          <p>
 */
public final class TypesMap {

    public static final String BOOLEAN = Boolean.class.getCanonicalName();

    public static final String SIMPLE_BOOLEAN = Boolean.class.getSimpleName();

    public static final String INTEGER = Integer.class.getCanonicalName();

    public static final String SIMPLE_INTEGER = Integer.class.getSimpleName();

    public static final String LONG = Long.class.getCanonicalName();

    public static final String SIMPLE_LONG = Long.class.getSimpleName();

    public static final String FLOAT = Float.class.getCanonicalName();

    public static final String SIMPLE_FLOAT = Float.class.getSimpleName();

    public static final String DOUBLE = Double.class.getCanonicalName();

    public static final String SIMPLE_DOUBLE = Double.class.getSimpleName();

    public static final String BIGDECIMAL = BigDecimal.class.getCanonicalName();

    public static final String SIMPLE_BIGDECIMAL = BigDecimal.class.getSimpleName();

    public static final String NUMBER = Number.class.getCanonicalName();

    public static final String SIMPLE_NUMBER = Number.class.getSimpleName();

    public static final String STRING = String.class.getCanonicalName();

    public static final String SIMPLE_STRING = String.class.getSimpleName();

    public static final String DATE = Date.class.getCanonicalName();

    public static final String SIMPLE_DATE = Date.class.getSimpleName();

    public static final String TIME = Time.class.getCanonicalName();

    public static final String SIMPLE_TIME = Time.class.getSimpleName();

    public static final String TIMESTAMP = Timestamp.class.getCanonicalName();

    public static final String SIMPLE_TIMESTAMP = Timestamp.class.getSimpleName();

    public static final String LBYTE = Byte[].class.getCanonicalName();

    public static final String SIMPLE_LBYTE = Byte[].class.getSimpleName();

    public static final String BLOB = Blob.class.getCanonicalName();

    public static final String SIMPLE_BLOB = Blob.class.getSimpleName();

    public static final String OBJECT = Object.class.getCanonicalName();

    public static final String SIMPLE_OBJECT = Object.class.getSimpleName();

    public static final String NULL = "null";

    public static final String[] TYPES = { BOOLEAN, INTEGER, LONG, FLOAT, DOUBLE, INTEGER, LONG, FLOAT, DOUBLE, BIGDECIMAL,
	    STRING, DATE, TIME, TIMESTAMP, LBYTE, BLOB, OBJECT, NULL };

    /**
     * 根据SQLType映射出对应的JAVA数据类型，并返回类型的简单名称。
     * 
     * @param sqlType SQLType
     * @return SQL Type 对应 JAVA Type的简单名称。
     * @see java.sql.Types
     */
    public static String getSimpleName(int sqlType) {
	switch (sqlType) {
	case Types.BIT:
	case Types.BOOLEAN:
	    return SIMPLE_BOOLEAN;

	case Types.TINYINT:
	case Types.SMALLINT:
	case Types.INTEGER:
	    return SIMPLE_INTEGER;

	case Types.BIGINT:
	    return SIMPLE_LONG;

	case Types.REAL:
	    return SIMPLE_FLOAT;

	case Types.FLOAT:
	case Types.DOUBLE:
	    return SIMPLE_DOUBLE;

	case Types.NUMERIC:
	case Types.DECIMAL:
	    return SIMPLE_BIGDECIMAL;

	case Types.CHAR:
	case Types.NCHAR:
	case Types.VARCHAR:
	case Types.NVARCHAR:
	case Types.LONGVARCHAR:
	case Types.LONGNVARCHAR:
	case Types.CLOB:
	case Types.NCLOB:
	    return SIMPLE_STRING;

	case Types.DATE:
	case Types.TIME:
	case Types.TIMESTAMP:
	    return SIMPLE_DATE;

	case Types.BINARY:
	case Types.VARBINARY:
	case Types.LONGVARBINARY:
	case Types.BLOB:
	    return SIMPLE_BLOB;

	case Types.JAVA_OBJECT:
	    return SIMPLE_OBJECT;

	case Types.NULL:
	    return NULL;

	default:
	    return "";
	}
    }

}
